import {
    MiddlewareConsumer,
    Module,
    NestModule,
    RequestMethod,
} from '@nestjs/common';
import { SysService } from './sys.service';
import { SysController } from './sys.controller';
import { LoggerMiddleware } from '@/common/middleware/logger.middleware';
import {
    SysUser,
    SysMenu,
    SysAction,
    SysMenuAction,
} from './entities/sys.entity';
import { TypeOrmModule } from '@nestjs/typeorm';
@Module({
    imports: [
        TypeOrmModule.forFeature([SysUser, SysMenu, SysAction, SysMenuAction]),
    ],
    controllers: [SysController],
    providers: [SysService],
    // exports: [SysUser]
})
export class SysModule implements NestModule {
    configure(consumer: MiddlewareConsumer) {
        // 三种方法 注册logger 中间件， 路由可以写成子路由
        // consumer.apply(LoggerMiddleware).forRoutes('sys');
        /* consumer.apply(LoggerMiddleware).forRoutes({
            path: 'sys',
            method: RequestMethod.GET,
        }); */
        consumer.apply(LoggerMiddleware).forRoutes(SysController);
    }
}
